﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace ShenRuQianChuChapt6Binding
{
    /// <summary>
    /// ControlASSource.xaml 的交互逻辑
    /// </summary>
    public partial class ControlASSource : Window
    {
        public ControlASSource()
        {
            InitializeComponent();
            //集合
            List<string> stringList = new List<string>() { "Tim", "Tom", "Blog" };

            this.textBox1.SetBinding(TextBox.TextProperty,new Binding("/") { Source = stringList});
            this.textBox2.SetBinding(TextBox.TextProperty, new Binding("/Length") { Source = stringList,Mode=BindingMode.OneWay });
            this.textBox3.SetBinding(TextBox.TextProperty, new Binding("/[2]") { Source = stringList,Mode=BindingMode.OneWay });

       
               
            //回家列表
            List<Contry> contryList = new List<Contry>()
            {
                new Contry()
                {
                    Name="中国",
                    ProvincesList= new List<Province>()
                    {
                        new Province()
                        {
                            Name="四川",
                            CityList = new List<City>()
                            {
                               new City(){ Name="成都"},
                               new City(){ Name="巴中"}
                            }
                        },
                        new Province()
                        { 
                            Name="山西",
                            CityList = new List<City>()
                            {
                               new City(){ Name="太原" },
                               new City(){  Name="运城" }
                            }
                        }                       
                    }
                 }            
            };
            this.textBox4.SetBinding(TextBox.TextProperty, new Binding("/Name") { Source = contryList });
            this.textBox5.SetBinding(TextBox.TextProperty, new Binding("/ProvincesList[0].Name") { Source = contryList});
            this.textBox6.SetBinding(TextBox.TextProperty, new Binding("/ProvincesList[0].CityList/Name") { Source = contryList});

        }
    }
}
